package org.yray.io.gcdemo;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lyg
 * @date 2021/9/12 11:04
 */

public class Main {

    public static void main(String[] args) throws InterruptedException {
        try {
            String str="q";
            //createString();
            //System.out.println(String.class.getClassLoader().getClass().getClassLoader().getClass().getClassLoader().getClass().getClassLoader().getClass().getClassLoader());
           /* URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs();
            for(URL url : urls){
                System.out.println(url.toExternalForm());
            }*/


        }catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
        Thread.sleep(5*3600*1000);
    }

    /**
     * 模拟CPU占满
     */

    public static  void testCPULoop() throws InterruptedException {
        System.out.println("请求cpu死循环");
        Thread.currentThread().setName("loop-thread-cpu");
        int num = 0;
        while (true) {
            num++;
            if (num == Integer.MAX_VALUE) {
                System.out.println("reset");
            }
            num = 0;
        }

    }

    /**
     * 模拟内存泄漏
     */

    public static  String leak() {
        System.out.println("模拟内存泄漏");
        ThreadLocal<Byte[]> localVariable = new ThreadLocal<Byte[]>();
        localVariable.set(new Byte[4096 * 1024]);// 为线程添加变量
        return "ok";
    }

    public static void createString()
    {
        Map<Long,String> map=new HashMap<>();
        StringBuffer sb = new StringBuffer();
        for(int i=0;i<100000;i++) {

            sb.append("abcdefgbnm");
        }
        sb.append(",findme");
        System.out.println("init");
        for(int j=0;j<50000;j++)
        {
            String meIsNew= new String(sb.toString()+j);
            //map.put(Long.valueOf(j),meIsNew);
            map.put(Long.valueOf(j),meIsNew.split(",")[1]);
            System.out.println("put:"+j);
            //leak();
        }
        System.out.println("finish");
    }
}
